/**
 *  预警预报应用深化-污染源分析-各城市大气排放流量分析
 *  Created by lins on 2018/7/17.
 */
'use strict';
angular.module("MetronicApp").directive('emissionMap', function () {
    return {
        scope: {
            id: "@",
            data: "="
        },
        restrict: 'EA',
        template: '',
        replace: true,
        link: function ($scope, element, attrs, controller) {
            var myChart = echarts.init(document.getElementById('second'), 'macarons');
            var uploadedDataURL = "./data/w/decisionAnalysis/prediction/pollutantSource/hebei.json";
            myChart.showLoading();
            $.getJSON(uploadedDataURL, function(geoJson) {
                echarts.registerMap('hebei', geoJson);
                myChart.hideLoading();
                var geoCoordMap = {
                    '张家口':[114.87,40.82],
                    '承德':[117.93,40.97],
                    '秦皇岛':[119.57,39.95],
                    '唐山':[118.02,39.63],
                    '廊坊':[116.7,39.53],
                    '保定':[115.48,38.85],
                    '沧州':[116.83,38.33],
                    '石家庄':[114.48,38.03],
                    '衡水':[115.72,37.72],
                    '邢台':[114.48,37.05],
                    '邯郸':[114.47,36.6]
                }
                var data = [
                    {name: '张家口', value: 441},
                    {name: '承德', value: 256},
                    {name: '秦皇岛', value: 165},
                    {name: '唐山', value: 394},
                    {name: '廊坊', value: 356},
                    {name: '保定', value: 334},
                    {name: '沧州', value: 185},
                    {name: '石家庄', value: 166},
                    {name: '衡水', value: 244},
                    {name: '邢台', value: 389},
                    {name: '邯郸', value: 500}
                ];
                var max = 480,
                    min = 9;
                var maxSize4Pin = 100,
                    minSize4Pin = 20;

                var convertData = function(data) {
                    var res = [];
                    for (var i = 0; i < data.length; i++) {
                        var geoCoord = geoCoordMap[data[i].name];
                        if (geoCoord) {
                            res.push({
                                name: data[i].name,
                                value:  geoCoord.concat(data[i].value),
                                data: data[i].value
                            });
                        }
                    }
                    return res;
                };

                var option = {
                    title : {
                        text: '各城市大气排放流量分析',
                        x:'center',
                        textStyle:{  //标题文字设置
                            fontSize: '20',
                            fontWeight: 'bold',
                            color: '#5AB1EF'
                        }
                    },
                    legend: {
                        y: 'bottom',
                        x: 'center',
                        data: ['2017年']
                    },
                    geo: {
                        map: 'hebei',
                        itemStyle: {
                            normal: {
                                areaColor: '#000000',
                                borderColor: '#ffffff'
                            },
                            emphasis: {  //鼠标经过状态-背景变色
                                show:false,
                                areaColor: '#000000'
                            }

                        }
                    },
                    series: [
                      /*  {
                            name: '2017',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            data: convertData(data),
                            symbolSize: function(val) {
                                return val[2] / 25;
                            },
                            label: {
                                normal: {
                                    formatter: '{b}',
                                    position: 'right',
                                    show: true,
                                    color:'#f4e925'
                                }
                            },
                            itemStyle: {
                                emphasis: {
                                    areaColor: '#f4e925'
                                }
                            }
                        },*/
                        {
                            name: '2017年',
                            type: 'effectScatter',
                            coordinateSystem: 'geo',
                            data: convertData(data.sort(function(a, b) {
                                return b.value - a.value;
                            }).slice(0, 15)),
                            symbolSize: function(val) {
                                return val[2] / 50;
                            },
                            showEffectOn: 'render',
                            rippleEffect: {
                                brushType: 'stroke'
                            },
                            hoverAnimation: true,
                            label: {
                                normal: {
                                    formatter: function(val) {
                                        return val.data.name + val.data.data;
                                        // return val.data.name + val.data.value[2];
                                    },
                                    position: 'right',
                                    show: true
                                }
                            },
                            itemStyle: {
                                normal: {
                                    color:'#f4e925',
                                }
                            },
                            zlevel: 1
                        }

                    ]
                };
                myChart.setOption(option);
            });
        }
    };
});

